<?php
/*********************/
/*                   */
/*  文章评论模块         */
/*   BY voiet        */
/*   2009-7-30       */
/*                   */
/*********************/

class cmd_comment extends mdl_comment
{

	function toartcomment( $data, $item, &$message )
	{
		$this->toinsert( $data );
		if ( $this->system->getconf( "comment.display.".$item ) == "soon" )
		{
			$message = $this->system->getconf( "comment.submit_display_notice.".$item );
		}
		else
		{
			$message = $this->system->getconf( "comment.submit_hidden_notice.".$item );
		}
		
		return true;
	}
	
	function getartmessbyid( $comment_id )
	{
		$aRet = $this->db->selectrow( "SELECT c.*, g.title AS article_name FROM sdb_comments c\n   LEFT JOIN sdb_articles g ON c.goods_id = g.article_id\n                    WHERE comment_id = ".intval( $comment_id ) );
		return $aRet;
	}
	
	function getartcomment( $limit,$type )
	{
		return $this->db->select( "SELECT c.title,c.time,c.comment_id,c.author,c.goods_id,c.comment FROM sdb_comments as c\n        WHERE c.for_comment_id is Null and c.display=\"true\" AND disabled='false' AND c.object_type='".$type."'  ORDER BY c.comment_id desc limit 0,".intval( $limit ) );
	}
	
	function getartindexcomments( $article_id, $item = "art152" )
	{
		
		$sql = "SELECT * FROM sdb_comments WHERE goods_id = ".intval( $article_id )." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true' ORDER BY p_index DESC, time DESC ";
		return $this->db->select( $sql );
	}
	
	function getartcommentlist( $article_id, $item = "art152", $page = 1 )
	{
		if ( $page < 1 )
		{
			$page = 1;
		}
		$pagenum = 6;
		$sql = "SELECT * FROM sdb_comments\n            WHERE goods_id = ".intval( $article_id )." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true'";
		$aRet['total'] = $this->db->_count( $sql );
		$maxPage = ceil( $aRet['total'] / $pagenum );
		if ( $maxPage < $page )
		{
			$page = $maxPage;
		}
		$start = ( $page - 1 ) * $pagenum;
		$start = $start < 0 ? 0 : $start;
		$sql = "SELECT * FROM sdb_comments\n            WHERE goods_id = ".intval( $article_id )." AND for_comment_id IS NULL AND object_type = '".$item.( "' AND display = 'true' and disabled='false' ORDER BY time DESC LIMIT ".$start."," ).$pagenum;
		$aRet['page'] = $maxPage;
		$aRet['data'] = $this->db->select( $sql );
		return $aRet;
	}
	

}

?>